package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.entity.enums.eWelfareActivityType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

public class BeautyFundActivityCondition extends BaseActivityCondition {
    public BeautyFundActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        int beautyCount = player.getModule(BeautyModule.class).getBeautyCount();
        setValue(BigInteger.valueOf(beautyCount));
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        ePlayerAttrType attrType;
        if (activityInfo.getChildType() == eWelfareActivityType.BeautyFund.getValue()) {
            attrType = ePlayerAttrType.BeautyFund;
        } else if (activityInfo.getChildType() == eWelfareActivityType.BeautyHigherFund.getValue()) {
            attrType = ePlayerAttrType.BeautyHigherFund;
        } else {
            return false;
        }
        if (activityConditionInfo.getParamList().get(0).compareTo(BigInteger.ONE) == 0) {//第一位是是否要購買過
            //是否購買了
            if (player.getModule(AttributeModule.class).getAttribute(attrType) == 1) {
                return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
            }
        } else if (activityConditionInfo.getParamList().get(0).compareTo(BigInteger.ZERO) == 0) {
            return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
        }
        return false;
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.BeautyFundNum.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.BeautyFundNum.getValue(), handle);
    }

    @Override
    public void initDefaultValue() {
        int beautyCount = player.getModule(BeautyModule.class).getBeautyCount();
        if (beautyCount > 0 ) {
            UserActivityConditionData userActivityConditionData = baseActivityData.getUserActivityConditionData(getConditionId());
            userActivityConditionData.setValue(BigInteger.valueOf(beautyCount));
        }
    }
}
